package com.swift.application.controller;

import com.swift.core.constant.CommonEnum;
import com.swift.core.menu.dto.MenuDto;
import com.swift.core.response.ResponseResult;
import com.swift.service.menu.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Ldanniel
 * @description :
 * @date 2022/07/10 18:31
 * @since open jdk 1.8
 */
@RestController
@RequestMapping("/menus")
public class MenuController {
    private final Logger logger = LoggerFactory.getLogger(MenuController.class);
    @Autowired
    private MenuService menuService;

    @PostMapping("/queryMenuInfo")
    public ResponseResult<Map<String, List<MenuDto>>> queryMenuInfo(){
        ResponseResult<Map<String, List<MenuDto>>> response = new ResponseResult<>(CommonEnum.SUCCESS);
        try{
            logger.info("获取按钮信息");
            Map<String, List<MenuDto>> menuRes = menuService.queryMenuInfo();
            response.setData(menuRes);
        }catch (Exception e){
            logger.error("获取按钮信息异常",e);
            response.setMessage(CommonEnum.FAILURE.getDescription());
            response.setStatus(CommonEnum.FAILURE.getCode());
        }
        return response;
    }
}
